import { BasicColumn, FormSchema } from '/@/components/Table';
import { useLimitOptions } from '/@/views/common/commonSetting';
import { toTimezone } from '/@/utils/dateUtil';
import { h } from 'vue';
import { Tooltip } from 'ant-design-vue';
import { useI18n } from '/@/hooks/web/useI18n';
import { setIpType, setIpType1 } from '../../common/ipLocation';
import dayjs from 'dayjs';
import { auths } from '/@/utils/authFunction';
const { limitOptions } = useLimitOptions();
const { t } = useI18n();
const setTooltip = (text) => {
  return h(
    Tooltip,
    {
      title: text,
    },
    () =>
      h(
        'div',
        {
          style: { whiteSpace: 'nowrap', textOverflow: 'ellipsis', overflow: 'hidden' },
        },
        text,
      ),
  );
};
export const schemas: FormSchema[] = [
  {
    field: 'created',
    label: '',
    component: 'Input',
    slot: 'created',
    ifShow: auths(['60111', '60109']),
  },
  // {
  //   field: 'start_time',
  //   component: 'DatePicker',
  //   labelPrefix: t('business.common_period_start'), //开始时间
  //   labelPrefixWidth: 75,
  //   colProps: { xxl: 6, xl: 6, lg: 6, md: 6, sm: 7 },
  //   slot: 'startDate',
  //   componentProps: {
  //     getPopupContainer: () => document.body,
  //   },
  // },
  // {
  //   field: 'end_time',
  //   component: 'DatePicker',
  //   labelPrefix: t('business.common_period_end'), //结束时间
  //   labelPrefixWidth: 75,
  //   colProps: { xxl: 6, xl: 6, lg: 6, md: 6, sm: 7 },
  //   slot: 'endDate',
  //   componentProps: {
  //     getPopupContainer: () => document.body,
  //   },
  // },
  {
    field: 'time',
    labelPrefix: t('business.time_limite'),
    labelPrefixWidth: 75,
    component: 'RangePicker',
    // defaultValue: [dayjs().startOf('day').toDate(), dayjs().endOf('day').toDate()],
    componentProps: {
      format: 'YYYY-MM-DD',
      placeholder: [t('business.common_start_time'), t('business.common_end_time')],
      getPopupContainer: () => document.body,
    },
  },
  {
    field: 'limit_type',
    component: 'Select',
    labelPrefix: t('modalForm.risk.risk_limit_type'), //限制类型
    colProps: { xxl: 6, xl: 6, lg: 6, md: 6, sm: 7 },
    defaultValue: 0,
    componentProps: {
      options: limitOptions,
    },
  },
  {
    field: '',
    component: 'Input',
    label: '',
    slot: 'currentType',
  },
  {
    field: 'username',
    component: 'Input',
    slot: 'username',
  },
  {
    field: 'cate',
    component: 'InputNumber',
    defaultValue: 3,
    show: false,
  },
];
export const columns: BasicColumn[] = [
  {
    title: t('business.common_email_account'), //邮箱账号
    dataIndex: 'val',
    minWidth: 280,
  },

  {
    title: t('modalForm.risk.risk_limit_type'), //限制类型
    dataIndex: 'created_at',
    minWidth: 242,
    customRender: ({ record }) => {
      return setIpType1(record);
    },
  },
  {
    title: t('business.common_remark'), //备注
    dataIndex: 'remark',
    width: 310,
    // customRender: ({ record }) => {
    //   return record.remarks ? setTooltip(record.remarks) : '-';
    // },
  },
  {
    title: t('business.common_operate'), //操作
    dataIndex: 'action',
    minWidth: 275,
    ifShow: auths(['60110', '60111']),
    slots: { customRender: 'action', style: { textAlign: 'center' } },
  },
  {
    title: t('table.risk.report_operate_people'), //操作人员
    dataIndex: 'updated_name',
    minWidth: 150,
  },
  {
    title: t('business.common_update_time'), //更新时间
    dataIndex: 'updated_at',
    minWidth: 330,
    customRender: ({ record }) => {
      return toTimezone(record.updated_at, 'YYYY-MM-DD HH:mm:ss');
    },
  },
];
